Skip to content

Conversation

@torosent
Copy link
Member

@torosent torosent commented Apr 24, 2025

This PR adds a user-agent header to the gRPC metadata in the DurableTaskSchedulerClientOptions.CreateChannel() method.

Why add a user-agent header?

  • Telemetry & Diagnostics: Including a user-agent string allows the Durable Task Scheduler backend to identify requests coming from the durabletask-dotnet SDK. This helps with usage tracking, diagnostics, and troubleshooting.
  • Version Awareness: The user-agent includes the SDK version (via DurableTaskUserAgentUtil.GetUserAgent()), making it easier to correlate issues or behaviors with specific client versions.
  • Best Practices: Sending a user-agent is a common best practice for SDKs and clients interacting with cloud services, enabling better support and analytics on the service side.

Summary of changes

  • The gRPC call interceptor now adds a user-agent header with the durabletask-dotnet SDK name and version to every outgoing request.

This change improves observability and supportability for both SDK users and service operators.


public static string GetUserAgent()
{
var version = typeof(DurableTaskUserAgentUtil).Assembly.GetName().Version;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code gets the assembly version, which is different from the DLL version and isn't really what we want. Use this instead:

Suggested change
var version = typeof(DurableTaskUserAgentUtil).Assembly.GetName().Version;
string version = FileVersionInfo.GetVersionInfo(typeof(DurableTaskUserAgentUtil).Assembly.Location).FileVersion;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make this into a readonly static value so that we read it only once and cache it rather than for every gRPC request.

static readonly string PackageVersion = FileVersionInfo.GetVersionInfo(typeof(DurableTaskUserAgentUtil).Assembly.Location).FileVersion;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


public static class DurableTaskUserAgentUtil
{
static string SdkName => "durabletask-dotnet";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static string SdkName => "durabletask-dotnet";
const string SdkName => "durabletask-dotnet";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

/// <summary>
/// Utility class for generating the user agent string for the Durable Task SDK.
/// </summary>
public static class DurableTaskUserAgentUtil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this public and why is it in the shared code? Since this is only used by the AzureManaged package, shouldn't it go into that project?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to the shared/azuremanaged

Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please update the CHANGELOG.md file at the root of this repo and I can sign off.

@cgillum cgillum merged commit c27770a into microsoft:main Apr 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants